define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'building/building/index' + location.search,
                    add_url: 'building/building/add',
                    edit_url: 'building/building/edit',
                    del_url: 'building/building/del',
                    multi_url: 'building/building/multi',
                    import_url: 'building/building/import',
                    table: 'building',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'floor_num', title: __('Floor_num')},
                        {field: 'area', title: __('Area'), operate:'BETWEEN'},
                        {field: 'zone', title: __('Zone')},
                        {field: 'images', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'user_id', title: __('User_id'), visible:false,switchable:false, addclass: 'selectpage', extend: 'data-source="user/user/index" data-field="nickname"'},
                        {field: 'username', title: __('User_id'), operate: false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'option',
                                    text: __('查看房间'),
                                    title: __('查看房间'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'building/room/index/build_id/{ids}',
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
